home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / FlightSim / scprintf.c < prev   
C/C++ Source or Header  |  1992-12-11  |  3KB  |  182 lines

  1. #include "flight.h"
  2.  
  3.  
  4. extern    GrafPtr            windManPort;
  5.  
  6.  
  7. static    long    rtrnAdrs;
  8. static    char    buffer[256];
  9.  
  10.  
  11. int        My_printf(char    *shwStr);
  12. OSErr    SendPort(char *buffer, int length);
  13.  
  14.  
  15. tprintf()
  16. {
  17.     asm    {
  18.         move.l    (sp)+,rtrnAdrs
  19.         }
  20.     sprintf(buffer);
  21.     SendPort(buffer, strlen(buffer));
  22.     asm    {
  23.         move.l    rtrnAdrs,a0
  24.         jmp        (a0)
  25.         }
  26. }
  27.  
  28. scprintf()
  29. {
  30.     asm    {
  31.         move.l    (sp)+,rtrnAdrs
  32.         }
  33.     sprintf(buffer);
  34.     My_printf(buffer);
  35.     asm    {
  36.         move.l    rtrnAdrs,a0
  37.         jmp        (a0)
  38.         }
  39. }
  40.  
  41. flprintf()
  42. {
  43.     asm    {
  44.         move.l    (sp)+,rtrnAdrs
  45.         }
  46.     sprintf(buffer);
  47. /*    AppendTempFile(buffer);*/
  48.     asm    {
  49.         move.l    rtrnAdrs,a0
  50.         jmp        (a0)
  51.         }
  52. }
  53.  
  54. static
  55. _My_printf(shwStr)
  56. char    *shwStr;
  57. {
  58.     char    buffer[256];
  59. static    Rect    dispRect = {67, 54, 87, 166};
  60.  
  61.     ClipRect(&dispRect);
  62.     EraseRect(&dispRect);
  63.     MoveTo(dispRect.left + 10, dispRect.bottom - 4);
  64.     strcpy(buffer, shwStr);
  65.     ctop(buffer);
  66.     DrawString(buffer);
  67. }
  68.  
  69. static
  70. My_printf(shwStr)
  71. char    *shwStr;
  72. {
  73.     char    buffer[256];
  74. static    Rect    dispRect = {21, 220, 40, 510};
  75.     GrafPtr    savePort;
  76.  
  77.     GetPort(&savePort);
  78.     SetPort(windManPort);
  79.         ClipRect(&dispRect);
  80.         EraseRect(&dispRect);
  81.         MoveTo(230, 36);
  82.         strcpy(buffer, (char *)shwStr);
  83.         ctop(buffer);
  84.         DrawString(buffer);
  85.     SetPort(savePort);
  86. }
  87.  
  88. static    IOParam        portParam;
  89.  
  90. /*** open printer port ***/
  91. OpenSerPort()
  92. {
  93.     portParam.ioCompletion = 0L;
  94.     portParam.ioNamePtr = (StringPtr)("\p.BOut");
  95.     portParam.ioRefNum = 0;
  96.     portParam.ioPermssn = fsWrPerm;
  97.     portParam.ioMisc = 0L;
  98.  
  99.     PBOpen(&portParam, FALSE);
  100. /*    if (portParam.ioResult)
  101.         if (portParam.ioResult EQ -98)
  102.             GenralAlert("\PAppleTalk connected; won't be able to print");
  103.         else
  104.             GenralAlert("\PError opening printer port");
  105. */
  106. }
  107.  
  108. static
  109. OSErr
  110. SendPort(buffer, length)
  111. char    *buffer;
  112. int        length;
  113. {
  114.     portParam.ioBuffer = buffer;
  115.     portParam.ioReqCount = length;
  116.     portParam.ioPosMode = fsAtMark;
  117.  
  118.     PBWrite(&portParam, FALSE);
  119.     buffer[portParam.ioActCount] = '\0';
  120.     return(portParam.ioResult);
  121. }
  122.  
  123.  
  124. #define    KEYMAP        ((long *)0x174)
  125.  
  126. KWait()
  127. {
  128. Boolean    ShiftDown();
  129. Boolean    OptionDown();
  130.  
  131.     if (OptionDown())
  132.         return;
  133.     while(!ShiftDown());
  134.     while(ShiftDown());
  135. }
  136.  
  137. Boolean
  138. ShiftDown()
  139. {
  140.     return(KEYMAP[1] & 1);
  141. }
  142.  
  143. Boolean
  144. OptionDown()
  145. {
  146.     return(KEYMAP[1] & 4);
  147. }
  148.  
  149. Boolean
  150. CommandDown()
  151. {
  152.     return((KEYMAP[1] & 0x8000) ? TRUE:FALSE);
  153. }
  154.  
  155. Boolean
  156. CapsDown()
  157. {
  158.     return(KEYMAP[1] & 2);
  159. }
  160.  
  161. Boolean
  162. CmndPeriod()
  163. {
  164.     EventRecord     keyEvent;
  165.  
  166.     if (GetNextEvent(keyDownMask, &keyEvent))    /* ROM */
  167.         if (keyEvent.modifiers & cmdKey)
  168.             if ((keyEvent.message & charCodeMask) EQ '.')
  169.                 return(TRUE);
  170.  
  171.     return(FALSE);
  172. }
  173.  
  174. /*** has the mouse button been pressed? ***/
  175. Boolean
  176. MousePress()
  177. {
  178.     EventRecord    msEvent;
  179.  
  180.     return(GetNextEvent(mDownMask, &msEvent));
  181. }
  182.